package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    //判断当前购物车是否存在该商品
    List<ShoppingCart> get(ShoppingCart shoppingCart);

    //更新购物车中商品的数量+1

    void update(ShoppingCart shoppingCart);

    //添加购物车
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time)VALUES" +
            " (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime}) ")
    void inset(ShoppingCart shoppingCart);

    //查看购物车
    @Select("select *from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> list(Long userId);

    //删除购物车中的一个商品
    void delete(ShoppingCart shoppingCart);

    //购物车商品数量大于1，数量减一
    void deleteOne(ShoppingCart cart);

    //清空购物车
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void clean(ShoppingCart shoppingCart);
}
